class Node:
    def __init__(self,val=0,next=None):
        self.val=val 
        self.next=next 

def solve(head):
    pre=None
    cur=head
    nxt=cur.next
    while cur:
        cur.next=pre
        pre=cur 
        cur=nxt 
        if nxt: nxt=nxt.next 
    return pre 

def build(lst):
    head=Node(lst[0])
    cur=head
    for i in range(1,len(lst)):
        cur.next=Node(lst[i])
        cur=cur.next 
    return head

def solve(head):
    text=head
    n=0
    while text:
        n+=1
        text=text.next
    pre=head 
    for i in range(int(n/2)): pre=pre.next 
    cur=pre.next 
    while cur:
        nxt=cur.next
        cur.next=pre 
        pre=cur
        cur=nxt
    cur=head
    for i in range(int(n/2)):
        if cur.val!=pre.val: return False 
        cur=cur.next 
        pre=pre.next 
    return True 

head=build([1,2,2,1])
print(solve(head))

head=build([1,2])
print(solve(head))
